package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    import flash.ui.*;
    import flash.utils.*;
    import com.greensock.*;

    public class GeneralInfoShell extends Sprite
    {
        var msgField:BigFieldNarrow;
        public var myXMLList:XMLList;
        var emailInputField:BigFieldNarrow;
        var mailForm:Sprite;
        var myUrl:String;
        var fadeSpeed:Number;
        var arrowSprite:Sprite;
        var nameSprite:Sprite;
        var nameInputField:BigFieldNarrow;
        var nameField:BigFieldNarrow;
        var submitSpriteHover:Sprite;
        var field1:BigFieldNarrow;
        var field2:BigFieldNarrow;
        var textFormat:TextFormat;
        var emailSprite:Sprite;
        var field3:BigFieldNarrow;
        var myRoot:MovieClip;
        var emailField:BigFieldNarrow;
        var submitField:BigFieldNarrow;
        var styler:StyleSheet;
        var submitSprite:Sprite;

        public function GeneralInfoShell(param1:MovieClip, param2:Number, param3:XMLList) : void
        {
            myUrl = "http://announcementtool.com/subscriber_add_emailonly.php";
            myRoot = param1;
            fadeSpeed = param2;
            myXMLList = param3.item;
            textFormat = new TextFormat();
            textFormat.font = new HelveticaLightEmbed().fontName;
            textFormat.size = 14;
            textFormat.letterSpacing = 0;
            textFormat.leading = -4;
            textFormat.leftMargin = 0;
            textFormat.rightMargin = 0;
            buildStyles();
            buildFields();
            buildMailForm();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            doResize();
            return;
        }

        function sendIOError(event:IOErrorEvent) : void
        {
            var _loc_2:Timer = null;
            msgField.field.text = "Error sending message";
            msgField.field.setTextFormat(textFormat);
            _loc_2 = new Timer(5000, 1);
            _loc_2.addEventListener(TimerEvent.TIMER, clearMessage);
            _loc_2.start();
            return;
        }

        function submitOut(event:MouseEvent)
        {
            TweenMax.to(submitSprite, fadeSpeed, {tint:6710886, overwrite:true});
            return;
        }

        function doResize() : void
        {
            field1.x = 0;
            var _loc_1:* = myRoot.unitW / 75;
            field1.scaleY = myRoot.unitW / 75;
            field1.scaleX = _loc_1;
            field2.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
            var _loc_1:* = myRoot.unitW / 75;
            field2.scaleY = myRoot.unitW / 75;
            field2.scaleX = _loc_1;
            field3.x = Math.round(8 * (myRoot.unitW + myRoot.gutterW));
            var _loc_1:* = myRoot.unitW / 75;
            field3.scaleY = myRoot.unitW / 75;
            field3.scaleX = _loc_1;
            mailForm.x = Math.round(field3.x);
            mailForm.y = Math.round(field3.y + field3.height + 5 * myRoot.unitW / 75);
            var _loc_1:* = myRoot.unitW / 75;
            nameField.scaleY = myRoot.unitW / 75;
            nameField.scaleX = _loc_1;
            nameInputField.x = 3;
            nameInputField.y = Math.round(nameField.y + nameField.height + 10 * myRoot.unitW / 75);
            var _loc_1:* = myRoot.unitW / 75;
            nameInputField.scaleY = myRoot.unitW / 75;
            nameInputField.scaleX = _loc_1;
            emailField.y = Math.round(nameInputField.y + nameInputField.height + 24 * myRoot.unitW / 75);
            var _loc_1:* = myRoot.unitW / 75;
            emailField.scaleY = myRoot.unitW / 75;
            emailField.scaleX = _loc_1;
            emailInputField.x = 3;
            emailInputField.y = Math.round(emailField.y + emailField.height + 10 * myRoot.unitW / 75);
            var _loc_1:* = myRoot.unitW / 75;
            emailInputField.scaleY = myRoot.unitW / 75;
            emailInputField.scaleX = _loc_1;
            submitField.x = 3;
            submitField.y = Math.round(emailInputField.y + emailInputField.height + 24 * myRoot.unitW / 75);
            var _loc_1:* = myRoot.unitW / 75;
            submitField.scaleY = myRoot.unitW / 75;
            submitField.scaleX = _loc_1;
            nameSprite.y = Math.round((nameInputField.y - 1));
            nameSprite.width = Math.round(4 * myRoot.unitW + 3 * myRoot.gutterW);
            nameSprite.height = Math.round(26 * myRoot.unitW / 75);
            emailSprite.y = Math.round((emailInputField.y - 1));
            emailSprite.width = Math.round(4 * myRoot.unitW + 3 * myRoot.gutterW);
            emailSprite.height = Math.round(26 * myRoot.unitW / 75);
            var _loc_1:* = Math.round((submitField.y - 1));
            submitSpriteHover.y = Math.round((submitField.y - 1));
            submitSprite.y = _loc_1;
            var _loc_1:* = Math.round(myRoot.unitW + myRoot.gutterW);
            submitSpriteHover.width = Math.round(myRoot.unitW + myRoot.gutterW);
            submitSprite.width = _loc_1;
            var _loc_1:* = Math.round(26 * myRoot.unitW / 75);
            submitSpriteHover.height = Math.round(26 * myRoot.unitW / 75);
            submitSprite.height = _loc_1;
            arrowSprite.x = Math.round(submitSprite.x + submitSprite.width - 8 * myRoot.unitW / 75);
            arrowSprite.y = Math.round(submitSprite.y + (submitSprite.height - arrowSprite.height) / 2);
            msgField.y = Math.round(submitField.y + submitField.height + 24 * myRoot.unitW / 75);
            var _loc_1:* = myRoot.unitW / 75;
            msgField.scaleY = myRoot.unitW / 75;
            msgField.scaleX = _loc_1;
            return;
        }

        function submitClick(event:MouseEvent)
        {
            sendData();
            return;
        }

        function submitOver(event:MouseEvent)
        {
            TweenMax.to(submitSprite, fadeSpeed, {tint:16724736, overwrite:true});
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function sendData() : void
        {
            var _loc_1:URLVariables = null;
            var _loc_2:URLRequest = null;
            var _loc_3:URLLoader = null;
            _loc_1 = new URLVariables();
            _loc_1.name = nameInputField.field.text;
            _loc_1.email = emailInputField.field.text;
            _loc_1.user_id = 82;
            _loc_1.sendresponse = "Sending...";
            msgField.field.text = "Sending message...";
            msgField.field.setTextFormat(textFormat);
            _loc_2 = new URLRequest(myUrl);
            _loc_2.data = _loc_1;
            _loc_2.method = URLRequestMethod.POST;
            _loc_3 = new URLLoader();
            _loc_3.dataFormat = URLLoaderDataFormat.TEXT;
            _loc_3.addEventListener(Event.COMPLETE, sendComplete);
            _loc_3.addEventListener(IOErrorEvent.IO_ERROR, sendIOError);
            _loc_3.load(_loc_2);
            return;
        }

        function keyDownListener(event:KeyboardEvent) : void
        {
            if (event.keyCode == Keyboard.ENTER)
            {
                sendData();
            }
            return;
        }

        function buildMailForm() : void
        {
            mailForm = new Sprite();
            addChild(mailForm);
            nameSprite = new Sprite();
            nameSprite.graphics.beginFill(15658734, 100);
            nameSprite.graphics.drawRect(0, 0, 1, 1);
            nameSprite.graphics.endFill();
            mailForm.addChild(nameSprite);
            emailSprite = new Sprite();
            emailSprite.graphics.beginFill(15658734, 100);
            emailSprite.graphics.drawRect(0, 0, 1, 1);
            emailSprite.graphics.endFill();
            mailForm.addChild(emailSprite);
            submitSprite = new Sprite();
            submitSprite.graphics.beginFill(6710886, 100);
            submitSprite.graphics.drawRect(0, 0, 1, 1);
            submitSprite.graphics.endFill();
            mailForm.addChild(submitSprite);
            nameField = new BigFieldNarrow();
            nameField.field.width = 243;
            nameField.field.autoSize = "left";
            nameField.field.embedFonts = true;
            nameField.field.antiAliasType = AntiAliasType.ADVANCED;
            nameField.field.gridFitType = GridFitType.PIXEL;
            nameField.field.defaultTextFormat = textFormat;
            nameField.field.text = "Name";
            nameField.field.textColor = 12303291;
            mailForm.addChild(nameField);
            nameInputField = new BigFieldNarrow();
            nameInputField.field.tabIndex = 0;
            nameInputField.field.width = 243;
            nameInputField.field.height = 18;
            nameInputField.field.type = TextFieldType.INPUT;
            nameInputField.field.antiAliasType = AntiAliasType.ADVANCED;
            nameInputField.field.gridFitType = GridFitType.PIXEL;
            nameInputField.field.embedFonts = true;
            nameInputField.field.defaultTextFormat = textFormat;
            nameInputField.field.text = "";
            nameInputField.field.textColor = myRoot.coldColor;
            mailForm.addChild(nameInputField);
            nameInputField.addEventListener(FocusEvent.FOCUS_IN, focusInListener);
            emailField = new BigFieldNarrow();
            emailField.field.width = 243;
            emailField.field.autoSize = "left";
            emailField.field.antiAliasType = AntiAliasType.ADVANCED;
            emailField.field.gridFitType = GridFitType.PIXEL;
            emailField.field.embedFonts = true;
            emailField.field.defaultTextFormat = textFormat;
            emailField.field.text = "Your Email";
            emailField.field.textColor = 12303291;
            mailForm.addChild(emailField);
            emailInputField = new BigFieldNarrow();
            emailInputField.field.tabIndex = 1;
            emailInputField.field.width = 243;
            emailInputField.field.height = 18;
            emailInputField.field.type = TextFieldType.INPUT;
            emailInputField.field.antiAliasType = AntiAliasType.ADVANCED;
            emailInputField.field.gridFitType = GridFitType.PIXEL;
            emailInputField.field.embedFonts = true;
            emailInputField.field.defaultTextFormat = textFormat;
            emailInputField.field.text = "";
            emailInputField.field.textColor = myRoot.coldColor;
            mailForm.addChild(emailInputField);
            emailInputField.addEventListener(FocusEvent.FOCUS_IN, focusInListener);
            submitField = new BigFieldNarrow();
            submitField.field.height = 28;
            submitField.field.autoSize = "left";
            submitField.field.antiAliasType = AntiAliasType.ADVANCED;
            submitField.field.gridFitType = GridFitType.PIXEL;
            submitField.field.defaultTextFormat = textFormat;
            submitField.field.selectable = false;
            submitField.field.text = "Submit Info";
            submitField.field.textColor = 16777215;
            submitField.field.alpha = 0.75;
            mailForm.addChild(submitField);
            submitSpriteHover = new Sprite();
            submitSpriteHover.graphics.beginFill(6710886, 0);
            submitSpriteHover.graphics.drawRect(0, 0, 1, 1);
            submitSpriteHover.graphics.endFill();
            submitSpriteHover.buttonMode = true;
            submitSpriteHover.useHandCursor = true;
            submitSpriteHover.addEventListener(MouseEvent.ROLL_OVER, submitOver, false, 0, true);
            submitSpriteHover.addEventListener(MouseEvent.ROLL_OUT, submitOut, false, 0, true);
            submitSpriteHover.addEventListener(MouseEvent.CLICK, submitClick, false, 0, true);
            mailForm.addChild(submitSpriteHover);
            arrowSprite = new Sprite();
            arrowSprite.graphics.beginFill(16777215, 100);
            arrowSprite.graphics.drawRect(0, 0, 1, 7);
            arrowSprite.graphics.drawRect(1, 1, 1, 5);
            arrowSprite.graphics.drawRect(2, 2, 1, 3);
            arrowSprite.graphics.drawRect(3, 3, 1, 1);
            arrowSprite.graphics.endFill();
            arrowSprite.buttonMode = true;
            arrowSprite.useHandCursor = true;
            mailForm.addChild(arrowSprite);
            msgField = new BigFieldNarrow();
            msgField.field.width = 283;
            msgField.field.autoSize = "left";
            msgField.field.antiAliasType = AntiAliasType.ADVANCED;
            msgField.field.gridFitType = GridFitType.PIXEL;
            msgField.field.embedFonts = true;
            msgField.field.defaultTextFormat = textFormat;
            msgField.field.text = "";
            msgField.field.textColor = 12303291;
            mailForm.addChild(msgField);
            addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
            return;
        }

        function clearForm() : void
        {
            nameInputField.field.text = "";
            emailInputField.field.text = "";
            return;
        }

        function clearMessage(event:Event) : void
        {
            msgField.field.text = "";
            return;
        }

        function buildFields() : void
        {
            field1 = new BigFieldNarrow();
            field1.field.width = 243;
            field1.field.autoSize = "left";
            field1.field.multiline = true;
            field1.field.wordWrap = true;
            field1.field.styleSheet = styler;
            field1.field.htmlText = "<p>" + myXMLList.specialNote + "</p>";
            addChild(field1);
            field2 = new BigFieldNarrow();
            field2.field.width = 243;
            field2.field.autoSize = "left";
            field2.field.multiline = true;
            field2.field.wordWrap = true;
            field2.field.styleSheet = styler;
            field2.field.htmlText = "<p>" + myXMLList.generalInfo + "</p>";
            addChild(field2);
            field3 = new BigFieldNarrow();
            field3.field.autoSize = "left";
            field3.field.selectable = false;
            field3.field.styleSheet = styler;
            field3.field.htmlText = "<p>Subscribe to our mailing list:</p>";
            addChild(field3);
            return;
        }

        function sendComplete(event:Event) : void
        {
            var _loc_2:URLVariables = null;
            var _loc_3:Timer = null;
            _loc_2 = new URLVariables(event.target.data);
            if (_loc_2.subscribe == "failure")
            {
                msgField.field.text = _loc_2.msg;
            }
            else if (_loc_2.subscribe == "success")
            {
                msgField.field.text = "You have been added to our mailing list";
                clearForm();
                _loc_3 = new Timer(5000, 1);
                _loc_3.addEventListener(TimerEvent.TIMER, clearMessage);
                _loc_3.start();
            }
            msgField.field.setTextFormat(textFormat);
            return;
        }

        function focusInListener(event:FocusEvent) : void
        {
            if (stage.displayState == StageDisplayState.FULL_SCREEN)
            {
                myRoot.closeFullscreen();
            }
            return;
        }

        function buildStyles() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:* = undefined;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:* = undefined;
            var _loc_8:Object = null;
            _loc_1 = new HelveticaLightEmbed().fontName;
            _loc_2 = new HelveticaBoldEmbed().fontName;
            styler = new StyleSheet();
            _loc_3 = new Object();
            _loc_3.color = myRoot.coldColorHTML;
            _loc_3.fontFamily = _loc_1;
            _loc_3.leading = -4;
            _loc_4 = new Object();
            _loc_4.color = myRoot.coldColorHTML;
            _loc_4.textDecoration = "none";
            _loc_5 = new Object();
            _loc_5.color = myRoot.hotColorHTML;
            _loc_5.textDecoration = "none";
            _loc_6 = new Object();
            _loc_6.color = myRoot.coldColorHTML;
            _loc_6.fontFamily = _loc_2;
            _loc_7 = new HelveticaItalicEmbed().fontName;
            _loc_8 = new Object();
            _loc_8.color = myRoot.coldColorHTML;
            _loc_8.fontFamily = _loc_7;
            styler.setStyle(".myItalic", _loc_8);
            styler.setStyle("p", _loc_3);
            styler.setStyle("a:link", _loc_4);
            styler.setStyle("a:hover", _loc_5);
            styler.setStyle(".mybold", _loc_6);
            return;
        }

    }
}
